package org.dubh.dp;

import com.google.common.base.Objects;
import com.google.common.base.Preconditions;

/**
 * A type of item that may be included in a {@link Knapsack}.
 */
public final class KnapsackItemType {
    private final int value;
    private final int cost;
    private final String description;
    
    /**
     * Creates a new knapsack item type.
     * 
     * @param value the value of items of this type.
     * @param cost the cost of items of this type.
     * @param description a description for items of this type.
     */
    public KnapsackItemType( int value, int cost, String description ) {
        Preconditions.checkArgument( value >= 0 );
        Preconditions.checkArgument( cost >= 0 );
        Preconditions.checkNotNull( description );
        
        this.value = value;
        this.cost = cost;
        this.description = description;
    }

    public int value() { return value; }
    public int cost() { return cost; }
    public String description() { return description; }

    @Override
    public int hashCode() {
        return Objects.hashCode( value, cost, description );
    }
    
    @Override
    public boolean equals( Object o ) {
        if ( o == this ) return true;
        if ( !(o instanceof KnapsackItemType ) ) return false;
        KnapsackItemType other = (KnapsackItemType) o;
        return other.value() == value() &&
               other.cost() == cost() &&
               Objects.equal( other.description(), description() );
    }
    
    @Override
    public String toString() {
        return String.format( "KnapsackItemType[description=%s,cost=%s,value=%s", 
                              description, cost, value );
    }
}